//
// File:	Trace.cpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Create:	20/01/2010 at 21:52:31
// Purpose:	
//

#include "Trace.hpp"

//------------------------------------------------------------------
// TraceStream
//------------------------------------------------------------------
Trace::TraceStream::TraceStream(const std::string &prefix)
	:	std::ostream(NULL),
		_prefix(prefix)
{
}

//------------------------------------------------------------------
// Trace Streams
//------------------------------------------------------------------
std::ostream Trace::log(NULL);
std::ostream Trace::debug(NULL);
std::ostream Trace::warning(NULL);
std::ostream Trace::error(NULL);

//------------------------------------------------------------------
// Set Level
//------------------------------------------------------------------
void Trace::setLevel(unsigned int iFlags)
{
	std::map<unsigned int, std::ostream *> streams;
	streams[Log] = &log;
	streams[Debug] = &debug;
	streams[Warning] = &warning;
	streams[Error] = &error;

	std::map<unsigned int, std::ostream *>::iterator it = streams.begin();
	std::map<unsigned int, std::ostream *>::iterator ite = streams.end();
	for (; it != ite; ++it)
	{
		it->second->rdbuf(NULL);
		if ((iFlags & it->first) == it->first)
		{
			it->second->rdbuf(std::clog.rdbuf());
		}
	}
}
